package com.avcdata.aoscustommade.utils.http;


import com.avcdata.aoscustommade.utils.AvcLogUtils;
import com.loopj.android.http.JsonHttpResponseHandler;

import org.apache.http.Header;
import org.json.JSONObject;

/**
 *
 * Created by zyh on 2017/5/19.
 */

public class AvcResponseHandler extends JsonHttpResponseHandler {

    /**
     * 请求开始时间
     */
    private long beginTime  = 0;

    /**
     * 请求url
     */
    private String url = "";
    private String jsonObject = "";

    public long getBeginTime() {
        return beginTime;
    }

    public void setBeginTime(long beginTime) {
        this.beginTime = beginTime;
    }

    public void setJsonObject(String jsonObject){
        this.jsonObject = jsonObject;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public AvcResponseHandler() {
    }

    @Override
    public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
        super.onFailure(statusCode, headers, responseString, throwable);
        AvcLogUtils.d("zqBaseLib", ">>>请求url:" + url + "请求参数:"+ jsonObject +  "  耗时：" + (System.currentTimeMillis() - beginTime));
    }

    @Override
    public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
        super.onFailure(statusCode, headers, throwable, errorResponse);
        AvcLogUtils.d("zqBaseLib", ">>>请求url:" + url + "请求参数:"+ jsonObject +  "  耗时：" + (System.currentTimeMillis() - beginTime));
    }


    @Override
    public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
        super.onSuccess(statusCode, headers, response);
        AvcLogUtils.d("zqBaseLib", ">>>请求url:" + url + "请求参数:"+ jsonObject +  "  耗时：" + (System.currentTimeMillis() - beginTime));
        AvcLogUtils.d("zqBaseLib", ">>>请求url:" + url + " response：" + response.toString());
    }

    @Override
    public void onCancel() {
        super.onCancel();
        AvcLogUtils.d("zqBaseLib", ">>>请求url:" + url + "请求参数:"+ jsonObject +  "  耗时：" + (System.currentTimeMillis() - beginTime));
    }
}
